package com.yjd.bi.user.dao.impl;

import java.util.List;
import java.util.Map;

import com.yjd.bi.user.dto.UserBaseInfoDto;
import com.yjd.bi.user.dto.UserRemainDto;
import com.yjd.bi.user.dto.UserTicketUsedDto;
import com.yjd.bi.user.model.UserStatisticInfoModel;
import org.springframework.stereotype.Component;

import com.yjd.bi.user.dao.IUserDao;
import com.yjd.bi.user.dto.UserRankDto;
import com.yjd.bi.user.model.UserModel;
import com.yjd.comm.base.dao.impl.BaseDaoImpl;

/**
 * <b>description</b>：微信分享红包数据访问层 <br>
 * <b>time</b>：2016-12-14 16:43:52 <br>
 * <b>author</b>： ready likun_557@163.com
 */
@Component("userDao")
public class UserDaoImpl extends BaseDaoImpl implements IUserDao {

	private static final String SQLMAPNAMESPACE = UserModel.class.getName();
	private static final String PKNAME = "user_id";

	@Override
	public String getPrimaryKeyName() {
		return PKNAME;
	}

	@Override
	public String getSqlmapNamespace() {
		return SQLMAPNAMESPACE;
	}
	
	@Override
	public List<UserRankDto> getRankUsers(int type, Map<String, Object> paramMap) {
		if(type==1){
			return this.getSqlMap(false).queryForList(this.getStatement("borrow_price_user"), paramMap);
		}else if(type==2){
			return this.getSqlMap(false).queryForList(this.getStatement("invest_price_user"), paramMap);
		}else if(type==3){
			return this.getSqlMap(false).queryForList(this.getStatement("recharge_price_user"), paramMap);
		}else{
			return this.getSqlMap(false).queryForList(this.getStatement("cash_price_user"), paramMap);
		}
	}

	@Override
	public List<UserStatisticInfoModel> queryChannelUserStatics(Map<String, Object> paramMap) {
		return this.getSqlMap(false).queryForList(this.getStatement("queryChannelUserStatics"), paramMap);
	}

	@Override
	public UserBaseInfoDto queryUserInfoById(Long user_id) throws Exception {
		return (UserBaseInfoDto)this.getSqlMap(false).queryForObject(this.getStatement("queryUserInfoById"), user_id);
	}

	public UserRemainDto queryUserRemainInfoById(Long user_id) throws Exception {
		return (UserRemainDto)this.getSqlMap(false).queryForObject(this.getStatement("queryRemainInfoById"), user_id);
	}

	@Override
	public UserTicketUsedDto queryUserTicketsUsedRecentlyById(Long user_id) {
		List list = this.getSqlMap(false).queryForList(this.getStatement("queryUserTicketsUsedRecentlyById"), user_id);
		return (list==null || list.size()==0) ? null : (UserTicketUsedDto)list.get(list.size()-1) ;
	}
}
